/**
* require PreferenceStringContainer.js
*/ 

function PreferencesController() {
    this.preferenceStringContainer = new PreferenceStringContainer();
	this.init();
}

PreferencesController.prototype = {
	init:	function(){
		
    },

	addAttack:	function(mywindow){
		openDialog('chrome://searchxss/content/addXss.xul', 'attackstring', 'chrome', mywindow,this);
	},

	removeAttack:	function(mywindow){
		var listbox = mywindow.document.getElementById("existingXSSstrings");
		var selectednode = listbox.getSelectedItem(0);
		for (var i = 0; node = listbox.childNodes[i]; i++){
			if (selectednode == node)
				break;
		}

		this.preferenceStringContainer.removeString(i);
		this.loadStrings(mywindow);
	},

	importAttacks:	function(){
        var data = "";
        var fileIn = Components.classes["@mozilla.org/file/local;1"]
                            .createInstance(Components.interfaces.nsILocalFile);
        fileIn.initWithPath("c:\\home");
        var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
                                .createInstance(Components.interfaces.nsIFileInputStream);
        istream.init(fileIn, 0x01, 0444, 0);

        var str = istream.read(4096);
        while (str.length > 0) {
          data += str;
          str = sstream.read(4096);
        }

        istream.close();
		alert('a');
	},

	loadStrings:	function(mywindow){
		var str = this.preferenceStringContainer.getStrings();
		var listbox = mywindow.document.getElementById("existingXSSstrings");

		while(listbox.childNodes.length>0){		
			listbox.removeChild(listbox.childNodes[0]);
		}

		for(var i=0;i<str.length;i++){		
			var listitem = mywindow.document.createElement("listitem");
			listitem.setAttribute("index",i);
			listitem.setAttribute("label",str[i]);
			listbox.appendChild(listitem);
		}
	}
};